var orderNumber=getvl("ids");
var oid=getvl("id");
 var exprid="";
 var brand="";
$(function(){
	  if(orderNumber!=''){
     $.ajax({
			url: urlcore + "/api/order/selectOrder?orderNumber="+orderNumber,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				if(data.success == true) {
					var da=data.data;
					 exprid=da.express.id;
					  if(da.express!=null){
					if(da.express.type==1){
						wuliu_fahuo_curr
						$("#kuaidier").attr("class","wuliu_fahuo_curr");
						$("#huoyuner").attr("class","");
						$("#kuaidisan").show();
						brand=da.express.brandName;
				$("#wuliumign").html(da.express.companyName);
				$("#bianhao").val(da.express.expressNumber);	
				
					}else{
						$("#kuaidier").attr("class","");
						$("#huoyuner").attr("class","wuliu_fahuo_curr");
						$("#huoyunsan").show();
						
						$("#huoyun").val(da.express.companyName);
						$("#yundanhaoma").val(da.express.expressNumber);
						var imds=da.express.expressImg;
						var idss="";
						if(imds!=null && imds!=""){
							var imgs=imds.split("***");
							$.each(imgs,function(y,n){
			idss+='<li><input type="hidden" value="'+n+'" class="classa" id="xijietu"/><img src="'+n+'"><span data-name="delete" onclick="shanchu(this)"></span></li>';
							});
						}
				
						$("#xiugaiss").append(idss);  						
					}
				}else{
					alert("异常");
				}
				}
			},
			error:function() {
				alert("error");
			}
		});
	  }else if(oid!=''){
				var	huoyun='<input type="button" value="确认发货" onclick="huoyunss()" class="public_input" />';
				var	huoyusn='<input type="button" value="确认发货" onclick="kuaidi()" class="public_input" />';
				$("#huoyunsss").html("");
				$("#querenfahuos").html("");
			    $("#querenfahuos").html(huoyusn);
				$("#huoyunsss").html(huoyun);
	  }
})




 //提交货运
   function querenfahuo(){
   	if(exprid!=''){
   		   var huoyun=$("#huoyun").val();
   		   var yundanhaoma=$("#yundanhaoma").val();
            var xijie="";
	    $(".classa").each(function(t,y){
	    	  xijie+=$(this).val()+"***";
	    	
	    });
	     var xijietupian=xijie.substring(0,xijie.length-3);	
		 $.ajax({
		url: urlcore + "/api/express/update",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
		oderid:orderNumber,
	    id:exprid,
        companyName:huoyun,
        expressImg:xijietupian,
        expressNumber:yundanhaoma,
        type:2,
        brandName:""
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				//alert("已修改");
		window.location.href=document.referrer;
		     }
		},error: function() {
			alert("error");
		}
	});
   	}else{
   		alert("异常");
   	}
   }
   
//提交物流
   function querenfahuo2(){
   	if(exprid!=''){
   		    var huoyun=$("#wuliumign").html();
   		    if(huoyun=="点击选择快递公司"){
   		    	alert("请选择快递公司");
   		    }else{
   		    	if(brand==''){
   		    		alert("请重新选择物流");
   		    	}else{
   		    var yundanhaoma=$("#bianhao").val();
    $.ajax({
		url: urlcore + "/api/express/update",
		type: "post",
		contentType: "application/json;charset=utf-8",
		data: JSON.stringify({
		oderid:orderNumber,	
        companyName:huoyun,
        expressNumber:yundanhaoma,
        type:1,
        brandName:brand,
        expressImg:""
		}),
		dataType: "json",
		success: function(data) {
			if(data.success == true) {
				//alert("已修改");
		window.location.href=document.referrer;
		     }
		},error: function() {
			alert("error");
		}
	});
   		}
	}
   	}else{
   		alert("异常");
   	}
   	
   }


function wulius(){
	      $("#shangquan").html("");
     $.ajax({
			url: urlcore + "/api/logistics/selectLogisticsList",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				if(data.success == true) {
					//alert(JSON.stringify(data.data))
					$.each(data.data, function(y,n) {
		var shangquan='<li onclick="shangquanid(this)" id="'+n.companyName+'" class="'+n.brandName+'">'+n.companyName+'</li>';
      $("#shangquan").append(shangquan);
					});
				}
			},
			error:function() {
				alert("error");
			}
		})
}


//删除数组元素
function removeByValues(val) {
  removeByValue(strs,val);
    strs.toString();
  weihuofabu(strs);
}




function shangquanid(te){
	 brand="";
   	  $("#wuliumign").html("");
    $("#wuliumign").html($(te).attr("id"));
    brand=$(te).attr("class");
     $('.payment_time_mask01').css("display","none");
}





function kuaidi(){
   var huoyun=$("#wuliumign").html();
   var bianhao=$("#bianhao").val();
	     if(huoyun!=null ||bianhao!=null){
	     	if(oid!=""){
	     	 $.ajax({
			url: urlcore +"/api/express/add?companyName="+huoyun+"&expressNumber="+bianhao+"&type=1&ids="+oid,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
				window.location.href=document.referrer;
			},
			error:function() {
				alert("error");
			}
		});
		}
	     }

	
	
	
}



function huoyunss(){   //wuliu fahuo
   var huoyun=$("#huoyun").val();
   var yundanhaoma=$("#yundanhaoma").val();
     var xijie="";
	    $(".classa").each(function(t,y){
	    	  xijie+=$(this).val()+"***";
	    });
	     var xijietupian=xijie.substring(0,xijie.length-3);
	     if(huoyun!=null ||yundanhaoma!=null){
	     	if(oid!=""){
	     	 $.ajax({
			url: urlcore + "/api/express/add?companyName="+huoyun+"&expressNumber="+yundanhaoma+"&expressImg="+xijietupian+"&type=2&ids="+oid,
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success:function(data){
					window.location.href=document.referrer;
			},
			error:function() {
				alert("error");
			}
		});
		}
	     }
}
